
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import("@/pages/home/home"),
      children: [
        { path: "/", name:"home",component: () => import("@/pages/home/first") },
        { path: "first", name: "first", component: () => import("@/pages/home/first") },
        { path: "city", name: "city", component: () => import("@/pages/home/city") },
      ]
    },
    {
      path: '/home', name: 'home', component: () => import("@/pages/home/home"),
      children: [
        { path: "/",name:"home", component: () => import("@/pages/home/first") },
        { path: "first", name: "first", component: () => import("@/pages/home/first") },
        { path: "city", name: "city", component: () => import("@/pages/home/city") },
      ]
    },
    //个人中心
    { path: '/personal', name: 'personal', component: () => import("@/pages/my/personal"),
    beforeEnter(to,from,next){
        if(sessionStorage.getItem("Userphone")){
          next();
        }else{
          next({
            path: '/login',
            query: { redirect: to.fullPath } // 将跳转的路由path作为参数，登录成功后跳转到该路由
          });
        }
       
    }
  },
    // 登录
    { path: "/login", name: "login", component: () => import("../pages/my/login.vue") },
    // 注册
    { path: "/register", name: "register", component: () => import("../pages/my/register.vue") },

    //个人中心设置页面
    { path: '/setup', name: 'setup', component: () => import("@/pages/my/setup") },
    //个个中心消息页面
    { path: '/message', name: 'setup', component: () => import("@/pages/my/message") },
    { path: '/mymenu', name: 'mymenu', component: () => import("@/pages/my/mymenu") },
    // 菜谱路由
    {
      path: '/menu',
      name: 'menu',
      component: () => import("@/pages/menu/menu")
    },
    {
      path: '/shop',
      name: 'shop',
      component: ()=>import("@/pages/shop/shop")
    },
    // 市集
    {
      path: '/market',
      name: 'market',
      component: () => import("@/pages/market/market")
    },
    //市集详情页面
    {
      path: '/detail', name: 'detail', component: () => import("@/pages/market/detail"),
      children: [
        { path: "", redirect: "detailText" },
        { path: "detailText", name: "detailText", component: () => import("@/pages/market/detailText") },
        { path: "detailSize", name: "detailSize", component: () => import("@/pages/market/detailSize") },
        { path: "addshopcar", name: "addshopcar", component: () => import("@/pages/market/addshopcar") },
        { path: "submitshopcar", name: "submitshopcar", component: () => import("@/pages/market/submitshopcar") },
      ]
    },
    // 交易页
    {
      path: '/deal', name: 'deal', component: () => import("@/pages/cart/deal")
    },
    // 订单完成页
    { path: '/complete', name: 'complete', component: () => import("@/pages/cart/complete") },
  ]
})


